package com.controller.Front;


import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.common.ajax.AjaxRes;
import com.common.mybatis.Page;
import com.common.utils.DateUtils;
import com.common.utils.base.UuidUtil;
import com.controller.base.BaseController;
import com.entity.ComplaintsSuggestions;
import com.entity.Users;
import com.service.ComplaintsService;
import com.service.UsersService;
/**
 * 前端页面诉求建议
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/frontSuggest/")
public class FrontSuggestionController  extends BaseController<Object>{
	//用户
	@Autowired
	private UsersService UserServ;
	
	
	//诉求建议
	@Autowired
	private ComplaintsService ComplaintsSer;
	/**
	 * 诉求建议
	 * @return
	 */
	@RequestMapping("/ShowSuggest")
	public ModelAndView ShowSuggest(){
		ModelAndView mv=new ModelAndView();
		mv.setViewName("FrontEnd/sqjy");
		return mv;
	}
	
	/**
	 * 诉求建议列表
	 * @param user
	 * @param page
	 * @param ClassId
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/SuggestContent")
	@ResponseBody
	public AjaxRes SuggestContent(Users user,Page<Users> page,String ClassId)throws Exception{
		AjaxRes res=new AjaxRes();
		Page<Users> newPages =UserServ.findPageByClassID(user, page,ClassId);
		res.setSucceed(newPages, "数据获取成功");
		return res;
	}
	
	/**
	 * 诉求建议详情
	 * @return
	 */
	@RequestMapping("/Info")
	public ModelAndView SuggestInfo(Users user){
		ModelAndView mv=new ModelAndView();
		List<Users> userlist=UserServ.find(user);
		mv.addObject("userlist", userlist.get(0));
		mv.setViewName("FrontEnd/SuggestInfo");
		return mv;
	}
	
	

	@RequestMapping("/Complaints")
	@ResponseBody
	public AjaxRes Complaints(ComplaintsSuggestions Suggestions)throws Exception{
		AjaxRes res=new AjaxRes();
		HttpSession session=getRequest().getSession();
		Users user=(Users)session.getAttribute("FrontUser");
		Suggestions.setComplaintsPeople(user.getUsersId());
		Suggestions.setComplaintsTime(DateUtils.getDate("yyyy/MM/dd HH:mm:ss"));
		Suggestions.setComplaintsSuggestionsId(UuidUtil.get32UUID());
		ComplaintsSer.insert(Suggestions);
		res.setResMsg("投诉成功");
		return res;
	}
}
